<template>
  <el-container style="height: 100%; border: 1px solid #eee">
    <div style="width: 200px;height: 100%;background-color: #dddddd">
    <el-aside width="200px" style="background-color: #dddddd">
      <el-menu router class="el-menu-vertical-demo" :default-openeds="open">
        <el-submenu v-show="item1.show" :index="index+''" :key="item1"  v-for="(item1,index) in list" >
          <template  slot="title" ><i :class="item1.icon" ></i>{{item1.name}}</template>
            <el-menu-item v-show="item2.show" :key="item2" :index="item2.path" v-for="item2 in item1.children">{{item2.name}}</el-menu-item>
        </el-submenu>
      </el-menu>
    </el-aside>
    </div>
    <el-container>
      <div class="el-header">
        <div class="avatar_index">
          <img class="logo_index" src="../assets/logo.jpg" alt />
        </div>
        <label class="name" @click="test">慢性病报销系统</label>
        <div class="role">
          <span >{{usermes.username}}</span>
          <el-button type="danger" style="margin-left: 50px" @click="outlogin">退出登录</el-button>
        </div>
      </div>
      <el-main>
        <router-view v-if="isRouterAlive"></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
import axios from 'axios'// 引入axios插件
export default {
  methods: {
    // 刷新
    reload () {
      this.isRouterAlive = false
      this.$nextTick(function () {
        this.isRouterAlive = true
      })
    },
    outlogin () {
      this.$router.push({ path: '/' })
    },
    test () {
      console.log(this.menulist.length)
    },
    // 读取菜单权限
    menufind () {
      for (var i = 0; i < this.menulist.length; i++) {
        this.menuset(this.menulist[i])
      }
    },
    menuset (menuitem) {
      switch (menuitem) {
        case '1级-系统管理':
          this.list[0].show = true
          break
        case '2级-用户管理':
          this.list[0].children[0].show = true
          break
        case '3级-添加用户':
          this.list[0].children[0].showadd = true
          break
        case '3级-修改用户':
          this.list[0].children[0].showedit = true
          break
        case '3级-删除用户':
          this.list[0].children[0].showdelete = true
          break
        case '2级-角色管理':
          this.list[0].children[1].show = true
          break
        case '3级-添加角色':
          this.list[0].children[1].showadd = true
          break
        case '3级-修改角色':
          this.list[0].children[1].showedit = true
          break
        case '3级-删除角色':
          this.list[0].children[1].showdelete = true
          break
        case '2级-菜单管理':
          this.list[0].children[2].show = true
          break
        case '3级-添加菜单':
          this.list[0].children[2].showadd = true
          break
        case '3级-修改菜单':
          this.list[0].children[2].showedit = true
          break
        case '3级-删除菜单':
          this.list[0].children[2].showdelete = true
          break
        case '2级-医疗机构管理':
          this.list[0].children[5].show = true
          break
        case '3级-添加医疗机构':
          this.list[0].children[5].showadd = true
          break
        case '3级-修改医疗机构':
          this.list[0].children[5].showedit = true
          break
        case '3级-删除医疗机构':
          this.list[0].children[5].showdelete = true
          break
        case '2级-慢性病分类管理':
          this.list[0].children[6].show = true
          break
        case '3级-添加慢性病分类信息':
          this.list[0].children[6].showadd = true
          break
        case '3级-修改慢性病分类信息':
          this.list[0].children[6].showedit = true
          break
        case '3级-删除慢性病分类信息':
          this.list[0].children[6].showdelete = true
          break
        case '2级-行政区域管理':
          this.list[0].children[3].show = true
          break
        case '3级-添加行政区域':
          this.list[0].children[3].showadd = true
          break
        case '3级-修改行政区域':
          this.list[0].children[3].showedit = true
          break
        case '3级-删除行政区域':
          this.list[0].children[3].showdelete = true
          break
        case '2级-农合经办点管理':
          this.list[0].children[4].show = true
          break
        case '3级-添加农合经办点':
          this.list[0].children[4].showadd = true
          break
        case '3级-修改农合经办点':
          this.list[0].children[4].showedit = true
          break
        case '3级-删除农合经办点':
          this.list[0].children[4].showdelete = true
          break
        case '1级-业务功能':
          this.list[1].show = true
          break
        case '2级-家庭档案管理':
          this.list[1].children[0].show = true
          break
        case '3级-添加家庭档案':
          this.list[1].children[0].showadd = true
          break
        case '3级-修改家庭档案':
          this.list[1].children[0].showedit = true
          break
        case '3级-删除家庭档案':
          this.list[1].children[0].showdelete = true
          break
        case '3级-查看家庭成员':
          this.list[1].children[0].find = true
          break
        case '4级-添加家庭成员':
          this.list[1].children[0].findadd = true
          break
        case '4级-修改家庭成员':
          this.list[1].children[0].findedit = true
          break
        case '4级-删除家庭成员':
          this.list[1].children[0].finddelete = true
          break
        case '2级-参合登记':
          this.list[1].children[1].show = true
          break
        case '3级-查找家庭成员':
          this.list[1].children[1].find = true
          break
        case '3级-录入参合信息':
          this.list[1].children[1].addshow = true
          break
        case '2级-慢性病证管理':
          this.list[1].children[2].show = true
          break
        case '3级-添加慢性病证':
          this.list[1].children[2].showadd = true
          break
        case '3级-修改慢性病证':
          this.list[1].children[2].showedit = true
          break
        case '3级-删除慢性病证':
          this.list[1].children[2].showdelete = true
          break
        case '2级-慢性病政策设置':
          this.list[1].children[3].show = true
          break
        case '3级-添加政策':
          this.list[1].children[3].showadd = true
          break
        case '3级-修改政策':
          this.list[1].children[3].showedit = true
          break
        case '3级-删除政策':
          this.list[1].children[3].showdelete = true
          break
        case '2级-慢性病报销':
          this.list[1].children[4].show = true
          break
        case '3级-查找参合人员':
          this.list[1].children[4].find = true
          break
        case '4级-报销登记':
          this.list[1].children[4].showadd = true
          break
        case '2级-报销记录查询':
          this.list[1].children[5].show = true
          break
        case '3级-审核报销信息':
          this.list[1].children[5].find = true
          break
      }
    }
  },
  created () {
    const _this = this
    axios.get('http://localhost:8088/getuser').then(function (resp) {
      _this.usermes = resp.data
      axios.get('http://localhost:8088/getmenus/' + resp.data.userid).then(function (resp1) {
        _this.menulist = resp1.data
        _this.menufind()
      })
    })
  },
  provide () {
    return {
      reload: this.reload,
      list: this.list
    }
  },
  data () {
    return {
      open: ['0', '1'],
      isRouterAlive: true,
      usershow: false,
      menulist: [],
      usermes: {
        username: '',
        role: '',
        pwd: '',
        sex: ''
      },
      list: [
        {
          path: '/',
          name: '系统设置（管理员）',
          icon: 'el-icon-user-solid',
          show: false,
          children: [
            {
              path: '/index/userlist',
              name: '用户管理',
              show: false,
              showadd: false,
              showedit: false,
              showdelete: false
            },
            {
              path: '/index/rolelist',
              name: '角色管理',
              show: false,
              showadd: false,
              showedit: false,
              showdelete: false
            },
            {
              path: '/index/menulist',
              name: '菜单管理',
              show: false,
              showadd: false,
              showedit: false,
              showdelete: false
            },
            {
              path: '/index/areaList',
              name: '行政区域管理',
              show: false,
              showadd: false,
              showedit: false,
              showdelete: false
            },
            {
              path: '/index/handleList',
              name: '农合经办点管理',
              show: false,
              showadd: false,
              showedit: false,
              showdelete: false
            },
            {
              path: '/index/chroniclist',
              name: '医疗机构管理',
              show: false,
              showadd: false,
              showedit: false,
              showdelete: false
            },
            {
              path: '/index/chronicfind',
              name: '慢性病分类管理',
              show: false,
              showadd: false,
              showedit: false,
              showdelete: false
            }
          ]
        },
        {
          path: '/',
          name: '业务功能',
          icon: 'el-icon-user-solid',
          show: false,
          children: [
            {
              path: '/index/familylist',
              name: '家庭档案管理',
              show: false,
              showadd: false,
              showedit: false,
              showdelete: false,
              find: false,
              findadd: false,
              findedit: false,
              finddelete: false
            },
            {
              path: '/index/canhelist',
              name: '参合登记',
              show: false,
              find: false,
              addshow: false
            },
            {
              path: '/index/chronicList1',
              name: '慢性病症管理',
              show: false,
              showadd: false,
              showedit: false,
              showdelete: false
            },
            {
              path: '/index/Zheng',
              name: '慢性病政策设置',
              show: false,
              showadd: false,
              showedit: false,
              showdelete: false
            },
            {
              path: '/index/baoxiaolist',
              name: '慢性病报销',
              show: false,
              find: false,
              showadd: false
            },
            {
              path: '/index/baoxiao',
              name: '慢性病报销记录查询',
              show: false,
              find: false
            }
          ]
        }
      ],
      list1: []
    }
  }
}
</script>
